{% extends 'layout/basic.html' %}
{% load static %}
{% block title %}
    用户登录
{% endblock %}
{% block css %}
    <style>
        .account {
            display: flex;
            justify-content: center;
        }

        h1 {
            text-align: center;
        }

        .error-msg {
            color: #1b6d85;
            position: absolute;
            font-size: 13px;
        }

        .form {
            background-image: url({% static 'image/img.png' %});
            background-size: 100% 100%;
            background-attachment: fixed;
            position: fixed;
            top: 250px;
            margin: 0 auto;
            border: 1px solid #5e5e5e;
            padding: 20px;
            border-radius: 10px;
            transition: transform 0.3s cubic-bezier(0.165, 0.84, 0.44, 1) !important;
            transform-style: preserve-3d !important;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.2) !important;
        }

        .form:hover {
            box-shadow: 0 0 25px rgba(0, 0, 0, 0.4) !important;
        }

        body {
            background-image: url({% static 'image/img10.jpg' %});
            background-size: cover;
            background-attachment: fixed;
            background-position: 50% 50%;
            background-repeat: no-repeat;
        }
    </style>
{% endblock %}


{% block content %}
    <div class="account">
        <div class="form">
            <h1>用户登录</h1>
            <form method="post" novalidate>
                {% csrf_token %}

                {% for field in form %}
                    {% if field.name == 'code' %}
                        <div class="form-group">
                            <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                            <div class="clearfix">
                                <div class="col-md-6" style="padding-left: 0;">
                                    {{ field }}
                                    <span class="error-msg">{{ field.errors.0 }}</span>
                                </div>
                                <div class="col-md-6">
                                    <img id="imageCode" src="{% url 'image_code' %}" alt="图片验证码">
                                </div>
                            </div>
                        </div>
                    {% else %}
                        <div class="form-group">
                            <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                            {{ field }}
                            <span class="error-msg">{{ field.errors.0 }}</span>
                        </div>
                    {% endif %}
                {% endfor %}
                <div>
                    <div style="float: right">
                        <a href="{% url 'login_sms' %}">短信验证码登录</a>
                    </div>
                </div>
                <div class="row">
                    <div class="col-xs-3">
                        <input type="submit" class="btn btn-primary" value="登  录"/>
                    </div>
                </div>
            </form>
        </div>

    </div>


{% endblock %}

{% block js %}
    <script>
        $(function () {
            $('#imageCode').click(function () {
                var oldSrc = $(this).attr('src');
                $(this).attr('src', oldSrc + '?');
            });
        });
    </script>
{% endblock %}


